import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import'
// import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// import postCssPxToRem from "postcss-pxtorem"
export default defineConfig({
	plugins: [
		vue(),
		vueJsx(),
		AutoImport({
			imports: ['vue', 'vue-router'],
			resolvers: [ElementPlusResolver()],
			eslintrc: {
				enabled: true
			}
		}),
		Components({
			resolvers: [ElementPlusResolver()],
		}),
	],
	base: "./",//打包路径
	resolve: {
		alias: {
			'@': path.resolve(__dirname, './src')//设置别名
		}
	},

	css: {
		preprocessorOptions: {
			// less: {},
			scss: {
				// 避免出现: build时的 @charset 必须在第一行的警告
				charset: false,
				additionalData: '@import "./src/styles/common.scss";'
			}
		},
		postcss: {
			plugins: [
				// postCssPxToRem({
				// 	rootValue: 192, // 1rem的大小
				// 	propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
				// })
			]
		}
	},
	server: {
		open: true,//启动项目自动弹出浏览器
		port: 4000,//启动端口
		// proxy: {
		// 	'/api_v3': {
		// 		target: 'https://dgmanage.digaokeji.cn/',	//实际请求地址
		// 		changeOrigin: true,
		// 		rewrite: (path) => path.replace(/^\/api_v3/, '')
		// 	},
		// }
	},
	build: {
		minify: 'terser',
		terserOptions: {
			compress: {
				//生产环境时移除console
				drop_console: true,
				drop_debugger: true,
			}
		},
		rollupOptions: {
			manualChunks(id) {
				if (id.includes('node_modules')) {
					return id.toString().split('node_modules/')[1].split('/')[0].toString()
				}
			}
		}
	}
	// server: {
	//   port: 4000,//启动端口
	//   open: true,
	//   proxy: {
	//     // 跨域简单写法写法
	//     '/api': 'http://123.56.85.24:5000'//代理网址
	//   },
	//   cors: true
	// },
})